home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-08-18 | 7.2 KB | 275 lines | [TEXT/R*ch] |
- (* Initialization of built-in units *)
-
- open List Fnlib Const Smlexc Prim Smlprim Globals Units Types;
-
- (* --- Global infix basis --- *)
-
- val std_infix_basis =
- [
- ("before", INFIXst 0),
- ("o", INFIXst 3), (":=", INFIXst 3),
- ("=", INFIXst 4), ("<>", INFIXst 4),
- ("<", INFIXst 4), (">", INFIXst 4),
- ("<=", INFIXst 4), (">=", INFIXst 4),
- ("@", INFIXRst 5), ("::", INFIXRst 5),
- ("+", INFIXst 6), ("-", INFIXst 6),
- ("^", INFIXst 6),
- ("div", INFIXst 7), ("mod", INFIXst 7),
- ("*", INFIXst 7), ("/", INFIXst 7)
- ];
-
- val () =
- app
- (fn(id, status) =>
- Hasht.insert pervasiveInfixTable id status)
- std_infix_basis
- ;
-
- (* --- Initial constructor basis --- *)
-
- val infoFalse = hd(initial_bool_CE)
- and infoTrue = hd(tl initial_bool_CE)
- and infoNil = hd(initial_list_CE)
- and infoCons = hd(tl initial_list_CE)
- and infoNONE = hd(initial_option_CE)
- and infoSOME = hd(tl initial_option_CE)
- and infoLESS = hd(initial_order_CE)
- and infoEQUAL = hd(tl initial_order_CE)
- and infoGREATER = hd(tl (tl initial_order_CE))
- and infoQUOTE = hd(initial_frag_CE)
- and infoANTIQUOTE = hd(tl initial_frag_CE)
- ;
-
- val initial_prim_basis =
- [
- ("/", (1, MLPdiv_real)),
- ("floor", (1, MLPccall(1, "sml_floor"))),
- ("ceil", (1, MLPccall(1, "sml_ceil"))),
- ("trunc", (1, MLPccall(1, "sml_trunc"))),
- ("round", (1, MLPccall(1, "sml_round"))),
- ("real", (1, MLPprim(1, Pfloatprim Pfloatofint))),
- ("^", (1, MLPconcat)),
- ("size", (1, MLPprim(1, Pstringlength))),
- ("!", (1, MLPprim(1, Pfield 0))),
- (":=", (1, MLPsetref)),
- ("not", (1, MLPprim(1, Pnot))),
- ("ignore", (1, MLPprim(1, Patom 0)))
- ];
-
- val initial_con_basis =
- [
- (* --- Constructors --- *)
- ("false", CONname (#info infoFalse)),
- ("true", CONname (#info infoTrue)),
- ("nil", CONname (#info infoNil)),
- ("::", CONname (#info infoCons)),
- ("NONE", CONname (#info infoNONE)),
- ("SOME", CONname (#info infoSOME)),
- ("LESS", CONname (#info infoLESS)),
- ("EQUAL", CONname (#info infoEQUAL)),
- ("GREATER", CONname (#info infoGREATER)),
- ("QUOTE", CONname (#info infoQUOTE)),
- ("ANTIQUOTE", CONname (#info infoANTIQUOTE)),
- ("ref", REFname),
- (* --- Overloaded operators --- *)
- ("=", VARname OVL2EEBo),
- ("<>", VARname OVL2EEBo),
- ("~", VARname OVL1NNo),
- ("abs", VARname OVL1NNo),
- ("+", VARname OVL2NNNo),
- ("-", VARname OVL2NNNo),
- ("*", VARname OVL2NNNo),
- ("div", VARname OVL2NNNo),
- ("mod", VARname OVL2NNNo),
- ("<", VARname OVL2NNBo),
- (">", VARname OVL2NNBo),
- ("<=", VARname OVL2NNBo),
- (">=", VARname OVL2NNBo),
- ("makestring", VARname OVL1NSo)
- ];
-
- (* *** Initial static environments *** *)
-
- (* Typing variable environment *)
-
- val sc_bool =
- trivial_scheme type_bool
- and sc_ii_i = trivial_scheme
- (type_arrow (type_pair type_int type_int) type_int)
- and sc_r_r = trivial_scheme
- (type_arrow type_real type_real)
- and sc_s_i = trivial_scheme
- (type_arrow type_string type_int)
- and sc_ss_s = trivial_scheme
- (type_arrow (type_pair type_string type_string) type_string)
- and sc_exn =
- trivial_scheme type_exn
- ;
-
- fun VEofCE (CE : ConEnv) =
- map (fn ci => (#id(#qualid ci), #conType(! (#info ci)))) CE
- ;
-
- val initial_eq_VE =
- [
- ("=", scheme_1u_eq (fn a =>
- type_arrow (type_pair a a) type_bool)),
- ("<>", scheme_1u_eq (fn a =>
- type_arrow (type_pair a a) type_bool))
- ];
-
- val initial_int_VE =
- [
- ];
-
- val initial_real_VE =
- [
- ("/", trivial_scheme
- (type_arrow (type_pair type_real type_real) type_real)),
- ("floor", trivial_scheme (type_arrow type_real type_int)),
- ("ceil", trivial_scheme (type_arrow type_real type_int)),
- ("trunc", trivial_scheme (type_arrow type_real type_int)),
- ("round", trivial_scheme (type_arrow type_real type_int)),
- ("real", trivial_scheme (type_arrow type_int type_real))
- ];
-
- val initial_string_VE =
- [
- ("^", sc_ss_s),
- ("size", sc_s_i)
- ];
-
- val initial_ref_VE =
- [
- ("ref", scheme_1u_imp (fn a =>
- type_arrow a (type_ref a))),
- ("!", scheme_1u (fn a =>
- type_arrow (type_ref a) a)),
- (":=", scheme_1u (fn a =>
- type_arrow (type_pair (type_ref a) a) type_unit))
- ];
-
- val sml_initial_VE = concat
- [
- VEofCE initial_bool_CE,
- initial_int_VE,
- initial_real_VE,
- initial_string_VE,
- VEofCE initial_list_CE,
- VEofCE initial_option_CE,
- VEofCE initial_order_CE,
- VEofCE initial_frag_CE,
- initial_ref_VE,
- [("not", trivial_scheme(type_arrow type_bool type_bool))],
- [("ignore", scheme_1u (fn a => type_arrow a type_unit))]
- ];
-
- val sml_initial_TE =
- [
- ("unit", tyname_unit),
- ("bool", tyname_bool),
- ("int", tyname_int),
- ("syserror", tyname_syserror),
- ("word", tyname_word),
- ("word8", tyname_word8),
- ("char", tyname_char),
- ("real", tyname_real),
- ("string", tyname_string),
- ("substring", tyname_substring),
- ("list", tyname_list),
- ("vector", tyname_vector),
- ("option", tyname_option),
- ("order", tyname_order),
- ("frag", tyname_frag),
- ("ref", tyname_ref),
- ("exn", tyname_exn),
- ("ppstream", tyname_ppstream)
- ];
-
- val generalExceptions =
- [ ("Io", 1, trivial_scheme(type_arrow type_of_io_exn type_exn))
- ];
-
- fun mkEmptyInfixBasis() =
- (Hasht.new 23 : (string, InfixStatus) Hasht.t)
- ;
-
- val () =
- app (fn (id, (arity,prim)) =>
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid={qual="General", id=id},
- info=PRIMname (mkPrimInfo arity prim) })
- initial_prim_basis
- ;
-
- val () =
- app (fn (id, ci) =>
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid={qual="General", id=id}, info=ci })
- initial_con_basis
- ;
-
- val () =
- app (fn (id, sc) =>
- Hasht.insert (#uVarEnv unit_General) id sc)
- sml_initial_VE
- ;
-
- val () =
- app (fn (id, tn) =>
- Hasht.insert (#uTyEnv unit_General) id tn)
- sml_initial_TE
- ;
-
- fun mkEi q arity =
- let val ei = mkExConInfo() in
- setExConArity ei arity;
- setExConTag ei (SOME (q, 0));
- ei
- end;
-
- val () =
- app (fn (id, ((q, stamp), arity)) =>
- let val q = {qual="General", id=id} in
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid=q, info=EXNname(mkEi q arity)}
- end)
- predefExceptions
- ;
-
- val () =
- app (fn (id, arity, sc) =>
- let val q = {qual="General", id=id} in
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid=q, info=EXNname(mkEi q arity)}
- end)
- generalExceptions
-
- ;
-
- val sc_str_exn = trivial_scheme (type_arrow type_string type_exn);
-
- val () =
- app (fn (id, sc) => Hasht.insert (#uVarEnv unit_General) id sc)
- (map (fn (id, (_, 0)) => (id, sc_exn)
- | (id as "SysErr", (_, 1)) => (id, trivial_scheme
- (type_arrow type_of_syserror_exn type_exn))
- | (id, (_, 1)) => (id, sc_str_exn)
- | (_, _) => fatalError "smlperv: ill-defined exception")
- predefExceptions)
-
- ;
-
- val () =
- app (fn (id, arity, sc) => Hasht.insert (#uVarEnv unit_General) id sc)
- generalExceptions
- ;
-
- val () =
- Hasht.insert pervSigTable "General" unit_General
- ;
-